<?php

/**
 * Base functionalty for for user and client model classes
 * @package Nina
 * @author John Main <john@thedaddy.org>
 */
abstract class Nina_Client_Model extends Nina_Model
{
	/**
	* Check if this is a guest user (i.e. not logged in)
	* @return boolean
	*/
	public function isGuest() {
		return $this->isNew();
	}

	/**
	* Check if this is logged in
	* @return boolean
	*/
	public function isLoggedIn() {
		return !$this->isNew();
	}

	/**
	* Check if this user is an administrator.
	* @return boolean
	*/
	public function isAdminLevel() {
		return ($this->getAdminLevel() == 'admin' || $this->getAdminLevel() == 'manager' || $this->getAdminLevel() == 'super');
	}

	/**
	* Check if this user is a manager.
	* @return boolean
	*/
	public function isAdmin() {
		return $this->getAdminLevel() == 'admin';
	}

	/**
	* Check if this user is a supervisor.
	* @return boolean
	*/
	public function isSupervisor() {
		return $this->getAdminLevel() == 'supervisor';
	}

	/**
	* Check if this user is a manager.
	* @return boolean
	*/
	public function isManager() {
		return $this->getAdminLevel() == 'manager';
	}

	/**
	* Check if this user is a super user.
	* @return boolean
	*/
	public function isSuper() {
		return $this->getAdminLevel() == 'super';
	}

	/**
	* Check if this user is a normal user.
	* @return boolean
	*/
	public function isUser() {
		return $this->getAdminLevel() == 'user';
	}

	/**
	* Get a textual version of the admin level
	* @return string
	*/
	public function getTextAdminLevel() {
		return self::textAdminLevel($this->getAdminLevel());
	}

	/**
	* Get a textual version of the admin level
	* @param string $level Admin lever
	* @return string
	*/
	public static function textAdminLevel($level) {
		$levels = array('user' =>'User',
					'admin' => 'Administrator',
					'manager' => 'Manager',
					'super' => 'Super User');
		return $levels[$level];
	}

	/**
	 * Quick function to get all the clients
	 * @return array
	 */
	public static function get() {
		return Client::doSelect(new Client(), Client::newCriteria());
	}

	/**
	* Base function for special user/client select conditions
	* Ready to be overloaded by User/Client class
	* @return Nina_Orm_Criteria
	*/
	public static function getSpecialConditionsCriteria() {
		return self::newCriteria();
	}
}
